# models.py
from django.db import models

import ChanPin.models


class ChanpinLeibie(models.Model):
    """产品类别"""
    name = models.CharField(verbose_name='类别名称', max_length=100, default="")
    description = models.TextField(verbose_name='描述', blank=True, null=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '产品类别'
        verbose_name_plural = '产品类别'


class Chanpin_gys(models.Model):
    """产品供应商"""
    name = models.CharField(verbose_name='供应商名称', max_length=22, default="")
    lxr = models.CharField(verbose_name='联系人', max_length=22, null=True)
    tel = models.CharField(verbose_name='联系电话', max_length=22, null=True)
    dizhi = models.CharField(verbose_name='联系地址', max_length=22, null=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '供应商'
        verbose_name_plural = '产品供应商'


class Chanpin(models.Model):
    """产品"""
    title = models.CharField(verbose_name='产品名称', max_length=22, default="")
    jiage = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='产品价格', null=True)
    jiage_dijia = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='产品底价', null=True)
    leibie = models.ForeignKey(ChanpinLeibie, on_delete=models.CASCADE, verbose_name='产品类别', null=True)
    gys = models.ForeignKey(Chanpin_gys, on_delete=models.CASCADE, verbose_name='产品供应商', default='')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '产品'
        verbose_name_plural = '产品'


#from xtuser.models import user
from django.contrib.auth.models import User #使用系统内置用户系统
from KeHu.models import KeHu
from django.conf import settings
from datetime import date


class Dingdan(models.Model):
    ddh = models.CharField(verbose_name='订单号', max_length=22, default="")
    ddtime = models.DateField(verbose_name='订单创建时间', auto_now=False, default=date.today)
    dduser = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='订单归属', default='',null=True)
    kehu = models.ForeignKey(KeHu, on_delete=models.CASCADE, verbose_name='订单客户', default='')
    ddchanpin = models.ManyToManyField(Chanpin, verbose_name='订单产品')

    def __str__(self):
        return self.ddh

    class Meta:
        verbose_name = '订单'
        verbose_name_plural = '用户订单'
